//
//  ByNetConfigApi.m
//  beibei_ios
//
//  Created by pro on 16/5/10.
//  Copyright © 2016年 hebidu. All rights reserved.
//

#import "ByNetConfigApi.h"

@implementation ByNetConfigApi

// 获取app配置
+ (void)requestRemoteGlobalConfigSuccess:(void(^)(ByNetBaseResult *result))success
                                 failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_Config_app";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%lf%d", [NSDate currentDateTimeInterval], rand];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:nil
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取配置成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           NSLog(@"******** 获取配置 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}


// 获取app版本信息
+ (void)requestAppVersionSuccess:(void(^)(ByNetBaseResult *result))success
                         failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"BY_Config_version";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%lf%d", [NSDate currentDateTimeInterval], rand];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:nil
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取app版本信息成功";
           result.data = responseObject;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           NSLog(@"******** 获取app版本信息 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];
}

@end
